package cn.zzuli.security.security;

import cn.zzuli.utils.utils.MD5;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Component;

/**
 * @Date: 2021/1/2 18:27
 * @Author: 绯色下午茶
 * @Description: 密码处理的工具类
 */
@Component
public class DefaultPasswordEncoder implements PasswordEncoder {
    public DefaultPasswordEncoder() {
        this(-1);
    }
    public DefaultPasswordEncoder(int length ) {
    }


    /**
     * 使用自定义的MD5加密方式
     * @param rawPassword
     * @return
     */
    @Override
    public String encode(CharSequence rawPassword) {
        String password = MD5.encrypt(rawPassword.toString());
        return password;

    }

    /**
     * 进行密码的比对
     * @param rawPassword        传输进来的密码
     * @param encodedPassword    加密之后的密码
     * @return
     */
    @Override
    public boolean matches(CharSequence rawPassword, String encodedPassword) {
        return encodedPassword.equals(MD5.encrypt(rawPassword.toString()));
    }
}
